

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Date;
import java.util.Timer;
import javax.swing.JFrame;
import javax.swing.JPanel;



public class MainWin extends JFrame implements KeyListener{
	
    public static final int LARGEUR = 800;
    public static final int HAUTEUR = 600;
    private Car agileCar ;
    private JPanel mainPanel;

    public MainWin(Car _car){
        this.agileCar = _car;

        this.mainPanel = new Fenetre(_car);
        this.mainPanel.setBackground(Color.WHITE);
        this.addKeyListener(this);
        this.setContentPane(this.mainPanel);
        this.setMinimumSize(new Dimension(LARGEUR, HAUTEUR));		
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.refresh();
    }

    public void displayCar(){
        //change by a method which effectivly modify the label position
        this.mainPanel.repaint();
    }

    public void refresh(){
        Timer leTimer = new Timer();
        int intervalleMillisec = 5;
        TimerRafraichissement laTacheALancer = new TimerRafraichissement(this);
        leTimer.schedule(laTacheALancer, new Date(), intervalleMillisec);
    }

    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {

        if (e.getKeyCode()==38)
        {
            agileCar.accelerer(1);
        }
        if (e.getKeyCode()==40)
        {
            agileCar.ralentir(1);
        }
        if (e.getKeyCode()==37)
        {
            agileCar.tournerGauche();
        }
        if (e.getKeyCode()==39)
        {
            agileCar.tournerDroite();
        }
        

    }

    @Override
    public void keyReleased(KeyEvent e) {
  
    }
        
        
        
        

}
